package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.Theme;
import cn.wolfcode.trip.base.mapper.ThemeMapper;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.IThemeService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ThemeServiceImpl implements IThemeService {


    @Autowired
    private ThemeMapper themeMapper;

    @Override
    public PageInfo<Theme> query(QueryObject qo) {
        PageHelper.startPage(qo
                .getCurrentPage(), qo.getPageSize());
        return new PageInfo<>(themeMapper.selectForList(qo));
    }

    @Override
    public void saveOrUpdate(Theme entity) {
        if (entity.getId() == null) {
            themeMapper.insert(entity);
        } else {
            themeMapper.updateByPrimaryKey(entity);
        }
    }

    @Override
    public List<Theme> list() {
        return themeMapper.selectAll();
    }

}
